/*子页面需要填写的内容：*/
function child(room_id){
	
	var id= room_id;
	$("#room_id").val(id);
	
	$.ajax({
		url:"../../facility/all",
		type:"post",
		dataType:"json",
		data:{
			"room_id":room_id
			
		},
		success:function(data){
			var content = "";
			var student=null;
			for (var i = 0; i < data.length; i++) {
				facility=data[i];
				content +='<tr>'
						+'<td>'+facility.f_name+'</td>'
						+'<td>'+facility.price+'</td>'
						+'<td>';
						if(facility.status==0){
							content	+='<a class="layui-btn layui-btn-sm" onclick="changeStatus('+facility.facility_id+')">正常</a>';
						}else if(facility.status==1){
							content	+='<a class="layui-btn layui-btn-sm layui-btn-danger" onclick="changeStatus('+facility.facility_id+')">损坏</a>';
						}else if(facility.status==2){
							content	+='<a class="layui-btn layui-btn-sm layui-btn-warm" onclick="changeStatus('+facility.facility_id+')">维修中</a>';
						}
				
				
				content+='</td>'
						+'<td>'
						+'<a class="layui-btn layui-btn-sm" onclick="deleteFacility('+facility.facility_id+')"><i class="layui-icon"></i>删除</a>'
						+'</td>'
						+'</tr>';
						
				
				
				
			}
			
			$("#facility").html(content);
			
			
		}

		
		
		
	});
//该方法相当于入口函数，进入该子页面即执行
}

//删除
function delCustomList(_this){
	layui.use(['form','laydate'], function() {
		layer.confirm('确定要删除么？', {
			btn: ['确定', '取消'] //按钮
		}, function() {
			$(_this).parent().parent().remove();
			layer.msg('删除成功', {
				icon: 1
			});
		}, function() {
			layer.msg('取消删除', {
				time: 2000 //20s后自动关闭
			});
		});
	});
}

//改变设施状态
function changeStatus(facility_id) {
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "修改状态",
			type: 2,
			area: ['50%', '40%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'facilityStatus.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(facility_id)
			}
		});
	});
}
//添加设备设施
function addFacility() {
	layui.use('layer', function() {
		var room_id = $("#room_id").val();
		
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "添加房间设施",
			type: 2,
			area: ['60%', '90%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'addFacility.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(room_id)
			}
		});
	});
}
//删除房间设施
function deleteFacility(facility_id){
	
	$.ajax({
		url:"../../facility/delete",
		type:"post",
		dataType:"json",
		
		data:{
			
			"facility_id":facility_id
		},
		success:function(data){
			if(data==0){
				alert("删除失败");
				location.reload();
			}else{
				
				location.reload();
			}
			
			
			
			
		}
	});
}

